<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>高度变化动画</title>
    <style>
        body{
            margin: 0;
            padding: 0;
        }
        #menu{
            width: 100px;
            height: 300px;
            border: 1px solid black;
            position: absolute;
            left: 400px;
            top: 100px;
        }
    </style>
</head>

<body>
    <!-- 方块 -->
    <div id="menu"></div>

    <script>
        // 获取元素
        var menuID = document.getElementById('menu');
        //  函数
        function fun(){
            // 获取元素样式
            var style = window.getComputedStyle(menuID);
            // 获取高
            var height = parseInt(style.height);
            // 判断高度是否到0
            if(height<=0){
                // 隐藏
            menuID.style.display = "none"; 
            }else{
                // 剪剪
                height--;
                //重新设置
                menuID.style.height = height+'px';
                // 延时
                setTimeout(fun,100)
            }
        }
        fun();






    </script>
</body>
</html>